class_name PlayerStateDiving
extends PlayerState

const DURATION_DIV := 500

var time_start_div := Time.get_ticks_msec()

func _enter_tree() -> void:
	var target_div := Vector2(player.spawn_position.x,ball.position.y)
	var direction := player.position.direction_to(target_div)
	if direction.y > 0:
		animation_player.play("dive_down")
	else:
		animation_player.play("dive_up")
	
	player.velocity = direction * player.SPEED
	
	time_start_div = Time.get_ticks_msec()
	
func _process(delta: float) -> void:
	if Time.get_ticks_msec() - time_start_div > DURATION_DIV:
		transaction_state(Player.State.RECOVERING)
